﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace BlankApp1.ViewModels
{
    class MyDialogViewModel : BindableBase, IDialogAware, INavigationAware
    {
        public event Action<IDialogResult> RequestClose;

        public string Title => "My Dialog";

        /// <summary>
        /// 是否可以关闭对话框
        /// </summary>
        /// <returns></returns>
        public bool CanCloseDialog() => true;

        /// <summary>
        /// 对话框关闭
        /// </summary>
        public void OnDialogClosed() { }

        /// <summary>
        /// 对话框打开
        /// </summary>
        public void OnDialogOpened(IDialogParameters parameters) { }

        /// <summary>
        /// 导航到
        /// </summary>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            MessageBox.Show("显示页面：打开对话框");
        }


        /// <summary>
        /// 是否是导航目标
        /// </summary>
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        /// <summary>
        /// 导航离开
        /// </summary>
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            MessageBox.Show("离开页面：关闭对话框");
        }


        /// <summary>
        /// 关闭对话框
        /// </summary>
        public DelegateCommand CloseCommand { get; private set; }

        public MyDialogViewModel()
        {
            CloseCommand = new DelegateCommand(() =>
            {
                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
            });
        }
    }
}
